/**********************************************************
 * UserShopAction.java 
 * Created by Ashutosh
 * Last modified Date: Nov 3, 2008 11:12:43 AM by Ashutosh
 * Revision: <svn revision #> 
 * Version : 0.1
 * Copyright (c) 2008 - 2009 cyberThink Infotech Pvt. Ltd., All rights reserved.
 **********************************************************/
package com.printeverywhere.action;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.ServletRequestAware;
import com.printeverywhere.delegator.ItemsServiceDelegator;
import com.printeverywhere.delegator.ShopSettingDelegator;
import com.printeverywhere.dto.Items;
import com.printeverywhere.dto.ShopSettings;
import com.printeverywhere.dto.Template;
import com.printeverywhere.dto.User;
import com.printeverywhere.util.AdminConstants;
import com.printeverywhere.util.SearchCriteria;
import com.printeverywhere.util.SessionUtil;

public class UserShopAction extends FrontBaseSupport implements
		ServletRequestAware {

	public UserShopAction() {
		super(false, false);
	}

	private static final long serialVersionUID = 1L;

	/** The request. */
	private HttpServletRequest request;

	private Logger logger = Logger.getLogger(UserShopAction.class);

	
	private ShopSettings shopSettings;
	

	private List<Items> itemsList;
	private Items items;
	private Map<Integer, Items> itemsMap;
	private int id;
	private int categoryId;

	private List<Items> categoryList;

	private Template template;

	public Template getTemplate() {
		return template;
	}

	public void setTemplate(Template template) {
		this.template = template;
	}

	public String getUserShop() throws Exception {
		try {
			if (request.getParameter("userId") != (null)) {
				id = Integer.parseInt(request.getParameter("userId"));
			} else {
				id = SessionUtil.getUser(request).getId();
			}
			if (request.getParameter(AdminConstants.CATEGORYID) != (null)) {
				categoryId = Integer.parseInt(request
						.getParameter(AdminConstants.CATEGORYID));
			}

			this.shopSettings = ShopSettingDelegator.getShopSettings(id);
			// this.shopSettings = new ShopSettings();
		
			// this.items = new Items();
			this.items = ItemsServiceDelegator.getItemsById(id);
			getItemList();
			
		} catch (Exception e) {
			logger.info("Error in displaying list.".intern());
			addActionError("Error in displaying list.".intern());
			return INPUT;
		}
		return SUCCESS;
	}


	private void getItemList() {
		SearchCriteria searchCriteria = new SearchCriteria();
		searchCriteria.setAttribute("userId", new User(id));
		if (categoryId > 0) {
			searchCriteria.setAttribute("generalCategories."
					+ AdminConstants.CATEGORYID, categoryId);
		}
		itemsList = ItemsServiceDelegator.getList(searchCriteria);
	}



	

	public List<Items> getItemsList() {
		return itemsList;
	}

	public void setItemsList(List<Items> itemsList) {
		this.itemsList = itemsList;
	}

	public Items getItems() {
		return items;
	}

	public void setItems(Items items) {
		this.items = items;
	}

	public Map<Integer, Items> getItemsMap() {
		return itemsMap;
	}

	public void setItemsMap(Map<Integer, Items> itemsMap) {
		this.itemsMap = itemsMap;
	}

	public void setServletRequest(HttpServletRequest arg0) {
		this.request = arg0;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public ShopSettings getShopSettings() {
		return shopSettings;
	}

	public void setShopSettings(ShopSettings shopSettings) {
		this.shopSettings = shopSettings;
	}

	public List<Items> getCategoryList() {
		return categoryList;
	}

	public void setCategoryList(List<Items> categoryList) {
		this.categoryList = categoryList;
	}

	public int getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(int categoryId) {
		this.categoryId = categoryId;
	}

}
